package com.ruoyi.hr.accumulationFund.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hr.accumulationFund.domain.HrAccumulationFund;
import com.ruoyi.hr.accumulationFund.service.IHrAccumulationFundService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公积金Controller
 *
 * @author xzshan
 * @date 2020-07-19
 */
@Controller
@RequestMapping("/hr/accumulationFund")
public class HrAccumulationFundController extends BaseController
{
    private String prefix = "hr/accumulationFund";

    @Autowired
    private IHrAccumulationFundService hrAccumulationFundService;

    @RequiresPermissions("hr:accumulationFund:view")
    @GetMapping()
    public String accumulationFund()
    {
        return prefix + "/accumulationFund";
    }

    /**
     * 查询公积金列表
     */
    @RequiresPermissions("hr:accumulationFund:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HrAccumulationFund hrAccumulationFund)
    {
        startPage();
        List<HrAccumulationFund> list = hrAccumulationFundService.selectHrAccumulationFundList(hrAccumulationFund);
        return getDataTable(list);
    }

    /**
     * 导出公积金列表
     */
    @RequiresPermissions("hr:accumulationFund:export")
    @Log(title = "公积金", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HrAccumulationFund hrAccumulationFund)
    {
        List<HrAccumulationFund> list = hrAccumulationFundService.selectHrAccumulationFundList(hrAccumulationFund);
        ExcelUtil<HrAccumulationFund> util = new ExcelUtil<HrAccumulationFund>(HrAccumulationFund.class);
        return util.exportExcel(list, "accumulationFund");
    }

    /**
     * 新增公积金
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存公积金
     */
    @RequiresPermissions("hr:accumulationFund:add")
    @Log(title = "公积金", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HrAccumulationFund hrAccumulationFund)
    {
        return toAjax(hrAccumulationFundService.insertHrAccumulationFund(hrAccumulationFund));
    }

    /**
     * 修改公积金
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        HrAccumulationFund hrAccumulationFund = hrAccumulationFundService.selectHrAccumulationFundById(id);
        mmap.put("hrAccumulationFund", hrAccumulationFund);
        return prefix + "/edit";
    }

    /**
     * 修改保存公积金
     */
    @RequiresPermissions("hr:accumulationFund:edit")
    @Log(title = "公积金", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HrAccumulationFund hrAccumulationFund)
    {
        return toAjax(hrAccumulationFundService.updateHrAccumulationFund(hrAccumulationFund));
    }

    /**
     * 删除公积金
     */
    @RequiresPermissions("hr:accumulationFund:remove")
    @Log(title = "公积金", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hrAccumulationFundService.deleteHrAccumulationFundByIds(ids));
    }
}
